package com.kangaroo.myhome.controller;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.kangaroo.myhome.model.TSysFile;
import com.kangaroo.myhome.service.impl.FileService;
import com.kangaroo.myhome.utils.SecurityUtils;
import com.kangaroo.myhome.vo.ResponseModel;

import tk.mybatis.mapper.util.StringUtil;

/**
 * @ClassName UploadController
 * @Description TODO
 * @Author kangaroo
 * @Date 2020/8/2 17:24
 * @Version 1.0
 **/

@RestController
@RequestMapping("fileConntroller")
public class FileController {

    @Autowired
    private FileService fileService;


    @GetMapping(value = "/findAll")
    public ResponseModel findAll(HttpServletRequest request) {
        ResponseModel model = new ResponseModel();
        String name = request.getParameter("name");
        String projectId = request.getParameter("projectId");
        String pageS = request.getParameter("page");
        String rowsS = request.getParameter("rows");
        int page = Integer.parseInt(pageS);
        int rows = Integer.parseInt(rowsS);
        if(StringUtil.isEmpty(projectId)){
            model.setCode(201);
            model.setMessage("请选择查看附件的项目");
            return model;
        }else{
            return fileService.findAll(name, projectId,page,rows);
        }
    }

    @PostMapping(value = "/delete")
    public ResponseModel delete(HttpServletRequest request) {
        ResponseModel model = new ResponseModel();
        String id = request.getParameter("id");
        if(StringUtil.isEmpty(id)){
            model.setCode(201);
            model.setMessage("请先选择要删除的附件");
            return model;
        }else{
            return fileService.delete(id);
        }
    }

}
